package dm71.espil;

import dm71.espil.FriendsListAdaptor.FriendHolder;
import dm71.espil.models.User;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * TODO Put here a description of what this class does.
 *
 * @author Moulde.
 *         Created Jan 9, 2012.
 */
public class AllUsersAdaptor extends ArrayAdapter<User>
{
	Context context;
	int layoutResourceID;
	User[] data = null;
	
	public AllUsersAdaptor(Context context, int layoutResourceID, User[] data)
	{
		super(context, layoutResourceID, data);
		this.layoutResourceID = layoutResourceID;
		this.context = context;
		this.data = data;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		View row = convertView;
		UserHolder holder = null;
		
		if(row == null)
		{
			LayoutInflater inflater = ((Activity)context).getLayoutInflater();
			row = inflater.inflate(layoutResourceID, null);
			
			holder = new UserHolder();
			holder.text = (TextView)row.findViewById(android.R.id.text1);
			row.setTag(holder);
		}
		else
		{
			holder = (UserHolder)row.getTag();
		}
		
		User user = data[position];
		holder.text.setText(user.getName() + " " + user.getLastName());
		
		return row;
	}
	
	static class UserHolder
	{
		TextView text;
	}
}
